import { Controller, Get, Post, Body, Param, Query } from '@nestjs/common';
import { DictService } from './dict.service';
import { CreateDictDto, QueryDictDto, UpdateDictDto, CreateDictItemDto, UpdateDictItemDto, QueryDictItemDto } from './dict.dto';

@Controller('admin/dict')
export class DictController {
  constructor(private readonly dictService: DictService) { }

  @Post('add')
  addDict(@Body() createDictDto: CreateDictDto) {
    return this.dictService.addDict(createDictDto);
  }

  @Get('page')
  getDictPage(@Query() queryDictDto: QueryDictDto) {
    return this.dictService.getDictPage(queryDictDto);
  }

  @Post('update')
  updateDict(@Body() updateDictDto: UpdateDictDto) {
    return this.dictService.updateDict(updateDictDto);
  }

  @Get(':id')
  getDictInfo(@Param('id') id: string) {
    return this.dictService.getDictInfo(+id);
  }

  @Post('del/:id')
  deleteDict(@Param('id') id: string) {
    return this.dictService.deleteDict(+id);
  }

  @Post('item/add')
  addDictItem(@Body() createDictItemDto: CreateDictItemDto) {
    return this.dictService.addDictItem(createDictItemDto);
  }

  @Get('item/page')
  getDictItemPage(@Query() queryDictItemDto: QueryDictItemDto) {
    return this.dictService.getDictItemPage(queryDictItemDto);
  }

  @Post('item/update')
  updateDictItem(@Body() updateDictItem: UpdateDictItemDto) {
    return this.dictService.updateDictItem(updateDictItem);
  }

  @Post('item/del/:id')
  deleteDictItem(@Param('id') id: string) {
    return this.dictService.deleteDictItem(+id);
  }

  @Get('type/:dictType')
  getDictItemByType(@Param('dictType') dictType: string) {
    return this.dictService.getDictItemByType(dictType);
  }
}
